<?php

namespace app\admin\model;

use think\Model;

class ProductPrice extends BaseModel
{
    public function discount()
    {
        return $this->hasMany(ProductDiscount::class, 'price_id', 'id');
    }

    public function currency()
    {
        return $this->hasOne(TransactionCurrency::class, 'id', 'transaction_currency_id');
    }

    /**
     * @describe
     * @author: Bobo
     * @date: 2025-07-15 13:39:43 
     * @param [type] @required
     * @return Renderable
     */
    public static  function getPriceFromInventory($inventoryId, $wid, $transactionCurrencyId)
    {
        $price = self::where([
            'inventory_id' => $inventoryId,
            'wid' => $wid,
            'transaction_currency_id' => $transactionCurrencyId,
            'is_del' => 0
        ])->with(['discount'])->find();
        if (!$price) {
            return [];
        }

        return $price->toArray();
    }
}
